package net.towee.client.managers;

import java.util.List;

import net.towee.client.event.core.ContactAddedEvent;
import net.towee.client.event.core.ContactRemovedEvent;
import net.towee.client.event.core.ContactsGroupChangedEvent;
import net.towee.client.event.core.ContactsGroupDeletedEvent;
import net.towee.client.event.core.UserAddedToContactsEvent;
import net.towee.client.event.core.UserRemovedFromContactsEvent;
import net.towee.model.account.AccountIdentity;
import net.towee.model.account.ContactsGroup;
import net.towee.shared.exceptions.NameExistsException;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * Manage contacts of account
 * 
 * <ul>The implementation MUST handler this PUSH events:
 * <li>When some user add current loged in user to his contacts - {@link UserAddedToContactsEvent}</li>
 * <li>When some user remove current loged in user from his contacts - {@link UserRemovedFromContactsEvent}</li>
 * </ul>
 * 
 * @author c58
 */
public interface ContactsManager {
	/**
	 * Create a new group of contacts. It save it on server and fire an event
	 * {@link ContactsGroupChangedEvent}. Also it put created ContactsGroup object
	 * to local store account data.
	 * 
	 * If group with given name already exists it invoke onFailure with
	 * {@link NameExistsException} exception instance.
	 * 
	 * @param name
	 * @return
	 */
	void createContactsGroup(String name, AsyncCallback<ContactsGroup> handler);

	/**
	 * It delete contacts group and fire an event
	 * {@link ContactsGroupDeletedEvent} and invoke onSuccess in handler
	 * with true, false otherwise.
	 * 
	 * @param id
	 */
	void deleteContactsGroup(String id, AsyncCallback<Boolean> handler);

	/**
	 * Rename group with given id. If success it fire an event
	 * {@link ContactsGroupChangedEvent}.
	 * 
	 * @param id
	 * @param newName
	 */
	void renameContactsGroup(String id, String newName, AsyncCallback<ContactsGroup> handler);

	/**
	 * Add accounts to contacts group with given ID.
	 * On success it fire an event {@link ContactAddedEvent} for each added contact.
	 * 
	 * @param id
	 * @param account
	 */
	void addContactsToGroup(String id, List<AccountIdentity> accounts, AsyncCallback<Boolean> handler);

	/**
	 * Remove contact from group
	 * On success it fire an event {@link ContactRemovedEvent} for each removed contact
	 * 
	 * @param id
	 * @param accountIds
	 */
	void removeContactFromGroup(String id, List<String> accountIds, AsyncCallback<Boolean> handler);
}
